import { localStg } from '@/utils';

/** 获取token */
export function getToken() {
  return localStg.get('token') || '';
}

/** 获取用户信息 */
export function getUserInfo() {
  const emptyInfo: Auth.UserInfo = {
    id: '',
    name: '',
    username: '',
    familyId: ''
  };
  return localStg.get('userInfo') || emptyInfo;
}

/** 去除用户相关缓存 */
export function clearAuthStorage() {
  localStg.remove('token');
  localStg.remove('userInfo');
}

/**
 * 设置token
 * @param token token值
 */
export function setToken(token: string) {
  localStg.set('token', token);
}

/**
 * 设置用户信息
 * @param userInfo 用户信息
 */
export function setUserInfo(userInfo: Auth.UserInfo) {
  localStg.set('userInfo', userInfo);
}
